﻿
// #define TEST

using System;

namespace UdpSubscriber
{
#if TEST

    class Tester
    {
        private UdpSubscriber m_subscriber = new UdpSubscriber("localhost",6001);

        void TestSubscriberChange()
        {
            m_subscriber.Start();

            Console.ReadLine();

            m_subscriber.Dispose();
        }

        static void Main(string[] args)
        {
            Tester tester = new Tester();
            tester.TestSubscriberChange();
        }
    }

#else
    class Program
    {
        static void Main(string[] args)
        {
            UdpSubscriber subscriber = new UdpSubscriber("localhost",6001);
            subscriber.PubMsgReceived += PrintMessage;

            subscriber.Start();
            Console.ReadLine();
            subscriber.Dispose();
        }

        static void PrintMessage(object source, PubReceivedEventArgs evtargs)
        {
            string msg = System.Text.Encoding.ASCII.GetString(evtargs.PubContent,0,evtargs.Length);
            Console.WriteLine("[RECEIVED]: {0}",msg);
        }
    }
#endif
}
